 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
 
import { priority } from "utils/constants/definetypes";
import { TaskHelper } from "utils/task/TaskHelper";
 
import { WarStrategy } from "utils/war/WarStrategy";

interface IEnemyStatus
{
    sum_heal: number;
    sum_damage: number;
    enemy_count: number;
    hostileCreeps: Creep[];
}
/**
 * 9房资源房战斗
 */
export class CenterRoomWarDecision< T extends "team"|"room"="team"|"room"> extends ABaseDecision<T>
{
    
    public isExpired(event: NormalEvent, region: string): boolean 
    {
         
        const room = Game.rooms[event.region] as Required<Room>;
        if(room.controller.level<7)
        {
           
            return false
        }
        const task = room.findTaskById(`${event.room}_defend`,"team");
        if(task)
        {
            
            return false;
        }
        return true;
    }
    public makeTask(event: NormalEvent, region: string): IDecisionCode<T>|false
    {
        const room = Game.rooms[event.region] as Required<Room>;
        const task = this.makeDefendTask(event);
        if(task)
        {
            const code:IDecisionCode<T>={
                region:event.region,
                isunique:false,
                task:[task as any ],
            }
            
            if(!Game.flags[task.id])
            {
                new RoomPosition(1,1,event.region).createFlag(task.id)
            }
            
            return code
        }
  
        return false;
        // return code
    }
    
    public makeDefendTask(event: NormalEvent  )
    {
        // const config:IBodyConfig={
        //     Role:"idaRed",
        //     body:[[MOVE,22],[ATTACK,18],[HEAL,5],[MOVE,1]]
        // }
        const team2Config:ITeamConfig={
            type:"Team2",
            creep:[
                [
                    {
                        Role:"idaRed",
                        
                        body:[ [MOVE,25],[ATTACK,20],[RANGED_ATTACK,5]]

                    },
                    1
                ],
                [
                    {
                        Role:"idaHeal",
                        
                        body:[  [MOVE,14], [HEAL,12],[MOVE,1]]
                    },
                    1
                ],
            ]
        };
        const wartask:ITeamTaskData<"defend">  ={
            type:"defend",
            room:event.room,
            arg:{
                benchRooms:[],
                enemy: [],
                structures:[],
            },
            cost:TaskHelper.getTaskPathCost(event.region,event.room),
            creeps:[],
            teams:{} as any,
            creepRequired:[ ] ,
            required:[[team2Config,1]],
        }
        const teamTask:ITaskDeclare["team"]=
        {
            id:`${event.room}_defend`,
            priority: priority.A,
            ttl: -1,
            type: "team",
            data: wartask,
            shard: 0,
            condition:{
                type:"taskFlag",
            }
        }
        return teamTask;
       
        // return undefined
    }
 
}